package com.dkt.android.mvp.ui.act

import android.os.Bundle
import android.widget.Button
import com.alibaba.android.arouter.facade.annotation.Route
import com.baidu.mapapi.map.*
import com.baidu.mapapi.model.LatLng
import com.dkt.android.R
import com.dkt.android.base.BaseActivity
import com.dkt.android.core.RouterHub


@Route(path = RouterHub.APP_MAP_ACTIVITY)
class BaiduMapActivity : BaseActivity() {

    private var mMapView : MapView? = null

    override fun getLayoutResource(): Int = R.layout.activity_map

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initView()
        initData()
    }

    private fun initData() {
        //定义Maker坐标点
        val point = LatLng(30.575041, 104.070734)
        //构建Marker图标
        val bitmap = BitmapDescriptorFactory
            .fromResource(R.mipmap.icon_marka)
        //构建MarkerOption，用于在地图上添加Marker
        val option: OverlayOptions = MarkerOptions()
            .position(point)
            .icon(bitmap)
        //在地图上添加Marker，并显示
        mMapView?.map?.addOverlay(option)

        val builder = MapStatus.Builder()
        //缩放级别
        builder.target(point).zoom(15.0f)
        //以指定坐标点进行显示
        mMapView?.map?.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()))

        //添加文字及信息窗
        //用来构造InfoWindow的Button
        val button = Button(applicationContext)
        button.setBackgroundResource(R.drawable.gray_radius)
        button.text = "环球中心"
        val mInfoWindow = InfoWindow(button, point, -50)
        //使InfoWindow生效
        mMapView?.map?.showInfoWindow(mInfoWindow)
    }
    private fun initView() {
        mMapView=findViewById(R.id.bmapView)
    }

    override fun onResume() {
        super.onResume()
        //在activity执行onResume时执行mMapView. onResume ()，实现地图生命周期管理
        mMapView?.onResume()
    }

    override fun onPause() {
        super.onPause()
        //在activity执行onPause时执行mMapView. onPause ()，实现地图生命周期管理
        mMapView?.onPause()
    }

    override fun onDestroy() {
        super.onDestroy()
        //在activity执行onDestroy时执行mMapView.onDestroy()，实现地图生命周期管理
        mMapView?.onDestroy()
    }
}